package 曾世昌12_19.demo4;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.Date;
import java.util.List;

public class MainApp {
    public static void main(String[] args) throws Exception {
        List<Element> bean = new SAXReader().read( "E:\\untitled5\\src\\rc\\demo12_19\\demo4\\eee.xml" ).getRootElement().elements( "bean" );
        for (Element element : bean) {
            Class<?> clazz = Class.forName( element.attributeValue( "className" ) );
            Object o = clazz.getConstructor().newInstance();
            List<Element> property = element.elements( "property" );
            DateConverter dateConverter = new DateConverter();
            dateConverter.setPatterns(new String[]{"yyyy-MM-dd"} );
            ConvertUtils.register( dateConverter, Date.class );
            for (Element element1 : property) {
                BeanUtils.setProperty( o, element1.attributeValue( "name" ), element1.attributeValue( "value" ) );
            }
            System.out.println(o);
        }

    }
}
